Skip to content

Conversation

@aidanharan
Copy link
Contributor

@aidanharan aidanharan commented Apr 2, 2020

MSSQL does not allow tables to be truncated if they have foreign key constraints. This is the cause of the ActiveRecord::StatementInvalid: TinyTds::Error: Cannot truncate table 'author_addresses' because it is being referenced by a FOREIGN KEY constraint. errors in the tests.

For the tests that involve truncating just one table I have removed the foreign key, performed the test and then restored the foreign key at the end.

I have coerced the test that truncates all tables as I would need to remove all foreign keys in all tables and then later restore them and I don't know an easy way of doing that.

References:

Before
https://travis-ci.org/github/rails-sqlserver/activerecord-sqlserver-adapter/jobs/669760945?utm_medium=notification&utm_source=github_status

6728 runs, 18647 assertions, 53 failures, 34 errors, 25 skips

After
https://travis-ci.org/github/rails-sqlserver/activerecord-sqlserver-adapter/jobs/670157194?utm_medium=notification&utm_source=github_status

6725 runs, 18638 assertions, 53 failures, 29 errors, 25 skips

Fixed namespacing

Fixed calls to coerce tests

Fix tests
@aidanharan aidanharan force-pushed the fix-truncation-tests branch from 68d08d1 to ebfd121 Compare April 2, 2020 13:55
@aidanharan aidanharan marked this pull request as ready for review April 2, 2020 14:14
@aidanharan aidanharan changed the title Add/remove foreign keys when truncating during tests Rails 6: Add/remove foreign keys when truncating during tests Apr 6, 2020
@aidanharan aidanharan mentioned this pull request Apr 6, 2020
@wpolicarpo wpolicarpo merged commit 8b48e5f into rails-sqlserver:6-0-dev Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants